package com.hospital.service.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import enhance.plus.logic.LogicBaseController;
import com.hospital.service.system.entity.SysLogInfo;
import com.hospital.service.system.entity.help.SysLogInfoHelp;
import com.hospital.service.system.model.param.SysLogInfoParam;
import com.hospital.service.system.service.SysLogInfoService;
import com.hospital.service.system.model.param.SysLogInfoQueryForOneRowParam;
import com.hospital.service.system.model.param.SysLogInfoQueryPageParam;
import com.hospital.service.system.model.vo.SysLogInfoVo;
import common.core.util.CommonUtil;
import common.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import enhance.plus.logic.LogicBaseController;
import enhance.plus.util.Page;
import enhance.plus.util.PageHelper;


import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


/**
 * 系统日志表 控制器
 *
 * @author AnKh
 * @created 2020-10-10 14:51:52
 */
@Slf4j
@Validated
@RestController
@Api(tags = "系统日志表")
@RequestMapping("/system/sysLogInfo")
public class SysLogInfoController extends LogicBaseController<SysLogInfoService, SysLogInfo> {

    @Autowired
    private SysLogInfoService sysLogInfoService;

    @ApiOperation(value = "保存系统日志表的数据")
    @RequestMapping(value = "/save" , method = RequestMethod.PUT)
    public Result save(@Valid @RequestBody SysLogInfoParam param){
        log.debug("开始保存系统日志表-->{}",param);
        return Result.success(this.sysLogInfoService.save(CommonUtil.copyBean(param,SysLogInfo.class)));
    }

    @ApiOperation(value = "更新系统日志表的数据")
    @RequestMapping(value = "/update" , method = RequestMethod.PUT)
    public Result update(@Valid @RequestBody SysLogInfoParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        log.debug("开始跟新系统日志表-->{}",param);
        return Result.success(this.sysLogInfoService.updateById(CommonUtil.copyBean(param,SysLogInfo.class)));
    }

    @ApiOperation(value = "删除系统日志表的一条数据")
    @RequestMapping(value = "/delete" , method = RequestMethod.DELETE)
    @ApiImplicitParams(
        @ApiImplicitParam(name= "id" ,value = "数据ID", required = true , example = "-1" )
    )
    public Result delete(@Valid @RequestParam @NotBlank(message = "删除数据ID不能为空") String id){
        log.debug("开始删除系统日志表的数据-->{}",id);
        return Result.success(this.sysLogInfoService.removeById(id));
    }

    @ApiOperation(value = "根据条件查询一条系统日志表的数据")
    @RequestMapping(value = "/queryForOneRow" , method = RequestMethod.POST)
    public Result<SysLogInfoVo> queryForOneRow(@Valid @RequestBody SysLogInfoQueryForOneRowParam param){
        //@TODO 请及时去修改 参数和返回值 的swagger 注解
        SysLogInfo row = this.sysLogInfoService.getOne(param.convertParamToQueryWapper());
        return Result.success( CommonUtil.copyBean(row, SysLogInfoVo.class));
    }

    @ApiOperation(value = "根据条件分页查询系统日志表的数据")
    @RequestMapping(value = "/queryPage" , method = RequestMethod.POST)
    public Result<Page<SysLogInfoVo>> queryPage(@Valid @RequestBody SysLogInfoQueryPageParam param){
        QueryWrapper<SysLogInfo> query = SysLogInfoHelp.createQuery();
        query.orderByDesc(SysLogInfoHelp.createTime);
        return Result.success(this.sysLogInfoService.page(param.page(),query));
    }

}
